﻿using System;
using EmbeddedSharp.Core;
using Zove.Runtime.Core.Expression;

namespace Zove.Runtime.Core.Zoom {
   
    /// <summary>
    /// Zoom expression
    /// </summary>
    public class ZoomExpression {

        private Node root;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="expr">the expression</param>
        /// <param name="model">runtime model</param>
        public ZoomExpression(string expr, RuntimeModel model) {
            ZoomExpressionParser p = new ZoomExpressionParser(expr, model);
            p.ConstantManager = DefaultDependencyManager.Instance.ConstantManager;
            p.FunctionManager = DefaultDependencyManager.Instance.FunctionManager;
            root = p.Parse();
        }

        /// <summary>
        /// Evaluate the expression
        /// </summary>
        /// <returns>result</returns>
        public object Evaluate()
        {
            object result = root.Evaluate();

            return result;
        }
    }
}
